function getQueryString(name) { 
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
        var r = window.location.search.substr(1).match(reg); 
        if (r != null) return unescape(r[2]); 
        return null; 
    }
//上传图片
function verify(val) {
	var file = document.getElementById("file") ? document.getElementById("file").files[0]:document.getElementById("file2").files[0];
	var imgtype = file.type
//	console.log("图片格式:"+imgtype)
	if(imgtype == "image/jpeg" || imgtype == "image/png") {
		var reader = new FileReader();
		reader.onload= function (e) {
			document.getElementById('imgdome') ? document.getElementById('imgdome').setAttribute('src', e.target.result):document.getElementById('imgdome2').setAttribute('src', e.target.result)
//			filer=e.target.result;
			main.response.photo=e.target.result
			yashuo(e.target.result)
        };
        reader.readAsDataURL(file);
     }else {
		log_message("请上传jpg或PNG格式的图片")
	}
}
function yashuo(filer){
	lrz(filer,{
		width:512
	})
	.then(function(rst){
		main.xgphoto=rst.base64.match(/base64,(\S*)/)[1]
	})
};
var ip=localStorage.ip;
var main = new Vue({
	el: '#main',
	data: {
		ip:localStorage.ip,
		weihu:true,
		xgphoto:'',
		response:{
			aboxx: null,
			address: "山东省烟台市牟平区文化街道办事处1133",
			createTime: null,
			csd: null,
			csrq: "1990-03-07",
			daStatus: null,
			gddh: null,
			gj: '156',
			havephone: null,
			hkdz: null,
			hyzk: null,
			id: "EL2018082014454017101839",
			isinjg: "1",
			jd: "文化街道办事处",
			jdcode: "370612002",
			jgid: "f80b940b-a514-4014-b2fd-dd9d97045a5c",
			jgname: "德信卫生服务中心",
			js1: null,
			js1Gx: null,
			js1Lxfs: null,
			js2: null,
			js2Gx: null,
			js2Lxfs: null,
			jw: null,
			jwCode: null,
			lastUpdatetime: null,
			lastUpdateuser: null,
			lun: "11",
			lxr: null,
			lxr2: null,
			lxr2Dz: null,
			lxr2Gx: null,
			lxr2Lxdh: null,
			lxrDz: null,
			lxrGx: null,
			lxrLxdh: null,
			mobilePhone: null,
			mph: "33",
			mz: '01',
			nfcid: null,
			nl: null,
			photo: null,
			qx: "牟平区",
			qxcode: "370612",
			resaddress: null,
			rhxx: null,
			sbkg: null,
			signStatus: null,
			source: "04",
			whcd: '15',
			xb: "1",
			xm: "张二杨",
			yxzt: null,
			zjhm: "370684199003073251",
			zy: null,
		},
	},
	 computed: {
	    reversedminzhu:function(){
	    		var zhi=''
		    	var this_=this
		    minzu.forEach(function(value,i){
		     	if(value.value==this_.response.mz){
		     		return zhi=value.text;
		     	}
			})
	    		return zhi;
	   },
	    reversedguojia:function(){
	    		var zhi=''
		    	var this_=this
		    guojia.forEach(function(value,i){
		     	if(value.value==this_.response.gj){
		     		return zhi=value.text;
		     	}
			})
	    		return zhi;
	    },
	    reversedhunyin:function(){
	    		var zhi=''
		    	var this_=this
		    hunyin.forEach(function(value,i){
		     	if(value.value==this_.response.hyzk){
		     		return zhi=value.text;
		     	}
			})
	    		return zhi;
	   },
	   reversedaboxx:function(){
	    		var zhi=''
		    	var this_=this
		    ABOxuexing.forEach(function(value,i){
		     	if(value.value==this_.response.aboxx){
		     		return zhi=value.text;
		     	}
			})
	    		return zhi;
	   },
	   reversedrhxx:function(){
	    		var zhi=''
		    	var this_=this
		    RHxuexing.forEach(function(value,i){
		     	if(value.value==this_.response.rhxx){
		     		return zhi=value.text;
		     	}
			})
	    		return zhi;
	   },
	   reversedguanxi:function(){
	    		var zhi=''
		    	var this_=this
		    guanxi.forEach(function(value,i){
		     	if(value.value==this_.response.lxrGx){
		     		return zhi=value.text;
		     	}
			})
	    		return zhi;
	   },
	   reversedwenhuacd:function(){
	    		var zhi=''
		    	var this_=this
		    wenhua.forEach(function(value,i){
		     	if(value.value==this_.response.whcd){
		     		return zhi=value.text;
		     	}
			})
	    		return zhi;
	   },
	 },
	methods:{
		xiugai:function(){
			ajaxPostJson(
				Url.ASSESS_UPDATEINFO,
				{
					'id':this.response.id,
					'xm':this.response.xm,
					'xb':this.response.xb,
					'nl':this.response.nl,
					'zjhm':this.response.zjhm,
					'photo':this.xgphoto,
					'mobilePhone':this.response.mobilePhone,
					'whcd':this.response.whcd,
					'csrq':this.response.csrq,
					'lxr':this.response.lxr,
					'lxrGx':this.response.lxrGx,
					'lxrDz':this.response.lxrDz,
					'lxrLxd':this.response.lxrLxd,
					'mz':this.response.mz,
					'hyzk':this.response.hyzk,
					'csd':this.response.csd,
					'address':this.response.address,
					'hkdz':this.response.hkdz,
					'aboxx':this.response.aboxx,
					'rhxx':this.response.rhxx,
					'zy':this.response.zy,
					'sbkg':this.response.sbkg,
					'gj':this.response.gj,
				},
				function(data){
					console.log(data)
					if(data.status=='1'){
						log_message('修改成功')
					}
				}
			)
		}
	}
})
if(getQueryString('sfzhm')){
	ajaxPost(
		Url.ASSESS_INFOBYZJHM,
		{
			"zjhm":getQueryString('sfzhm'),
		},
		function(data){
			console.log(data)
			if(data.status=='1'){
				data.response.photo=ip+data.response.photo;
				main.response=data.response;
			}
		}
	)
}else{
	main.weihu=false;
	main.response=JSON.parse(sessionStorage.pgoldinfo||'{}');
}
(function($, doc) {
	$.init();
	$.ready(function() {
		var _getParam = function(obj, param) {
			return obj[param] || '';
		};
		//民族
		var userPicker = new $.PopPicker();
		userPicker.setData(minzu);
		var showUserPickerButton = doc.getElementById('showUserPicker');
		showUserPickerButton.addEventListener('tap', function(event) {
			userPicker.show(function(items) {
				main.response.mz=items[0].value;
			});
		}, false);
		//国家
		var userPicker2 = new $.PopPicker();
		userPicker2.setData(guojia);
		var showUserPickerButton2 = doc.getElementById('showUserPicker2');
		showUserPickerButton2.addEventListener('tap', function(event) {
			userPicker2.show(function(items) {
				main.response.gj=items[0].value;
			});
		}, false);
		//婚姻
		var userPicker3 = new $.PopPicker();
		userPicker3.setData(hunyin);
		var showUserPickerButton3 = doc.getElementById('hunyinzk');
		showUserPickerButton3.addEventListener('tap', function(event) {
			userPicker3.show(function(items) {
				main.response.hyzk=items[0].value;
			});
		}, false);
		//abo血型
		var userPicker4 = new $.PopPicker();
		userPicker4.setData(ABOxuexing);
		var showUserPickerButton4 = doc.getElementById('aboxuexing');
		showUserPickerButton4.addEventListener('tap', function(event) {
			userPicker4.show(function(items) {
				main.response.aboxx=items[0].value;
			});
		}, false);
		//RH血型
		var userPicker5 = new $.PopPicker();
		userPicker5.setData(RHxuexing);
		var showUserPickerButton5 = doc.getElementById('rhxuexing');
		showUserPickerButton5.addEventListener('tap', function(event) {
			userPicker5.show(function(items) {
				main.response.rhxx=items[0].value;
			});
		}, false);
		//关系
		var userPicker6 = new $.PopPicker();
		userPicker6.setData(guanxi);
		var showUserPickerButton6 = doc.getElementById('lxrgx');
		showUserPickerButton6.addEventListener('tap', function(event) {
			userPicker6.show(function(items) {
				main.response.lxrGx=items[0].value;
			});
		}, false);
		//文化程度
		var userPicker7 = new $.PopPicker();
		userPicker7.setData(wenhua);
		var showUserPickerButton7 = doc.getElementById('wenhuacd');
		showUserPickerButton7.addEventListener('tap', function(event) {
			userPicker7.show(function(items) {
				main.response.whcd=items[0].value;
			});
		}, false);
	});
})(mui, document);